package com.dycx.user.converter;

import java.util.Date;

import cn.hutool.core.bean.BeanUtil;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dycx.user.entity.WalletLogDO;
import com.dycx.user.vo.WalletLogVO;
import com.dycx.user.dto.WalletLogDTO;

/**
 * 资金明细(WalletLog)实体转换类
 *
 * @author makejava
 * @since 2024-08-10 16:05:15
 */


@Data
public class WalletLogConverter implements Serializable {
    public static WalletLogDO dtoToEntity(WalletLogDTO dto) {
        if (dto == null) return null;
        WalletLogDO entity = BeanUtil.toBean(dto, WalletLogDO.class);
        return entity;
    }

    public static WalletLogVO entityToVo(WalletLogDO entity) {
        if (entity == null) return null;
        WalletLogVO vo = BeanUtil.toBean(entity, WalletLogVO.class);

        return vo;
    }

    public static List<WalletLogVO> entityToVoList(List<WalletLogDO> entityList) {
        List<WalletLogVO> voList = new ArrayList<>();
        for (WalletLogDO entity : entityList) {
            voList.add(entityToVo(entity));
        }
        return voList;
    }

    public static Page<WalletLogVO> entityToVoPage(Page<WalletLogDO> page) {

        List<WalletLogVO> newRecords = new ArrayList<>();

        List<WalletLogDO> records = page.getRecords();
        for (WalletLogDO entity : records) {
            newRecords.add(entityToVo(entity));
        }

        Page<WalletLogVO> voPage = new Page<>();
        voPage.setRecords(newRecords);
        voPage.setPages(page.getPages());
        voPage.setTotal(page.getTotal());
        voPage.setSize(page.getSize());
        voPage.setCurrent(page.getCurrent());

        return voPage;
    }

}
